import { PokerHand, cards2letter } from "./PokerHand.js";
import { PokerCard } from "../PokerCard.js";
import { BombPokerHand } from "./BombPokerHand.js";
export type { PokerCard, PokerType } from "../PokerCard.js";

/** 三带一单 */
export class ThirdWithSinglePokerHand extends PokerHand {
  public value: number;
  constructor(cards: PokerCard[]) {
    super(cards);
    this.value = this.cards[2].value;
  }

  /**
   * 判断是否为三带一：数值相同的三张牌 + 一张单牌。例如： 333+6
   * @param cards 手牌
   * @returns
   */
  public static isStandard(cards: PokerCard[]) {
    if (cards.length !== 4) {
      return false;
    }
    if (BombPokerHand.isStandard(cards)) {
      return false;
    }
    const str = cards2letter(cards);
    return /([A-O])\1{2}/g.test(str);
  }
  public isStandard = ThirdWithSinglePokerHand.isStandard;
  public isBetter(target: PokerHand): boolean {
    if (target instanceof ThirdWithSinglePokerHand && target.cards.length === this.cards.length) {
      return this.value > target.value;
    }

    return false;
  }
}

export default ThirdWithSinglePokerHand;
